package com.woniu.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.entity.AlarmSetting;
import com.woniu.entity.Charger;
import com.woniu.entity.ChargingStation;
import com.woniu.service.AlarmSettingService;
import com.woniu.service.ChargerService;
import com.woniu.service.ChargingStationService;
import com.woniu.util.PageData;
import com.woniu.util.ResponseData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("alarm")
@Slf4j
@CrossOrigin(origins = "*")
public class AlarmSettingController {

    @Autowired
    private AlarmSettingService alarmSettingService;

    /*
    * 充电站
    * */
    @Resource
    private ChargingStationService chargingStationService;

    /*
     * 充电桩
     * */
    @Resource
    private ChargerService chargerService;



    @RequestMapping("/chargerListC")
    public List<Charger> chargerListC(@RequestBody Map<String, Object> param) {
        List<Charger> chargerInfo = chargingStationService.chargerListC(param);
        return chargerInfo;
    }


    /*
    * 分页, 条件查询
    * */
    @RequestMapping("pageQuery")
    public ResponseData<PageData> pageQuery(@RequestBody PageData pageData){
       Page page = alarmSettingService.pageQuery(pageData);
       return ResponseData.ok(page);
    }
    /*
    * 新增
    * */
    @PostMapping("save")
    public ResponseData saveSetting(@RequestBody Map param){
        log.info("前端传来的数据: {}", param);
        alarmSettingService.saveSetting(param);

        return ResponseData.ok();
    }

    /*
    * 查看
    * */
    @GetMapping("getId")
    public ResponseData getId(@RequestParam Long id){
         log.info("传来的id:{}", id);
         AlarmSetting setting = alarmSettingService.getId(id);
         return ResponseData.ok(setting);
    }

    /*
    * 修改
    * */
    @RequestMapping("updateSetting")
    public ResponseData updateSetting(@RequestBody Map<String, Object> param){
        log.info("修改数据: {}", param);
        alarmSettingService.updateSetting(param);

        return ResponseData.ok();
    }
/*
* 删除
* */
    @DeleteMapping("deleteSetting")
    public ResponseData deleteSetting(@RequestParam List<Long> alarmIds){
        alarmSettingService.deleteSetting(alarmIds);
        return ResponseData.ok();
    }

    /*
    * 修改状态
    * */
    @PostMapping("updateStatus/{status}/{id}")
    public ResponseData updateStatus(@PathVariable Integer status, @PathVariable Long id){
        log.info("状态---> {}", status, "id---> {}", id);
        alarmSettingService.updateStatus(status, id);

        return ResponseData.ok();
    }

    @GetMapping("/settingExcel")
    public ResponseData<?> outDepartmentExcelTemplate(HttpServletResponse response) throws IOException {
        return alarmSettingService.outDepartmentExcelTemplate(response);
    }
}
